package demo1;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * Created with  IntelliJ IDEA .
 * Description:
 * User: lenovo
 * Date: 2025-${ MONTH }-25
 * Time: 15:23
 */

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public int compareTo(Student o){
        return this.age-o.age;
    }
}

public class Test {

    public static void mySort(Student[] students){

        for (int i = 0; i < students.length-1; i++) {
            for (int j = 0; j < students.length-1-i; j++) {
                if(students[j].compareTo(students[j+1]) < 0){
                    Student temp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = temp;
                }
            }
        }
    }

    public static void main1(String[] args) {

        Student[] students = new Student[3];

        students[0] = new Student("zhangsan",19);
        students[1] = new Student("lisi",55);
        students[2] = new Student("wangwu",16);

        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();

        Arrays.sort(students,ageComparator);

        System.out.println(Arrays.toString(students));

        Arrays.sort(students,nameComparator);

        System.out.println(Arrays.toString(students));

        int ret = ageComparator.compare(students[0],students[1]);
        int ret1 = nameComparator.compare(students[0],students[1]);

        System.out.println(ret);
        System.out.println(ret1);

        /*mySort(students);

        System.out.println(Arrays.toString(students));*/



    }




}
